package com.cqw.datamodel.sort;

import java.util.Arrays;

/**
 * @Author: caoqingwen
 * @CreateTime: 2021-11-16 16:29
 * @Description: 插入排序
 */
public class Insertion {


    public static void main(String[] args) {
        int[] arr = {3, 2, 5, 10, 12, 1, 9, 4};

        for (int i = 1; i < arr.length; i++) {
            for (int j = i; j > 0; j--) {
                if (arr[j - 1] > arr[j]) {
                    int temp = arr[j - 1];
                    arr[j - 1] = arr[j];
                    arr[j] = temp;
                }
            }
        }
        System.out.println(Arrays.toString(arr));
    }

}
